package com.ctshk.app.order.scenic.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.scenic.dto.ScenicOrderDTO;
import com.ctshk.rpc.order.scenic.dto.ScenicOrderDetailDTO;
import com.ctshk.rpc.order.scenic.dto.ScenicOrderIntegralExchangeDTO;
import com.ctshk.rpc.order.scenic.dto.ScenicOrderPayQueryInfoDTO;
import com.ctshk.rpc.order.scenic.dto.app.AppScenicOrderDTO;
import com.ctshk.rpc.order.scenic.req.*;
import com.ctshk.rpc.order.scenic.service.app.IAppScenicOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(value = "景点门票订单", tags = "景点门票订单")
@RestController
@RequestMapping("/order")
public class ScenicOrderController extends BaseController {
    @DubboReference
    IAppScenicOrderService iAppScenicOrderService;

    @GetMapping("/findScenicOrderInfoByNumber/{number}")
    @ApiOperation(value = "景点门票-根据单号或者查询单号获取订单详情", notes = "获取订单详情")
    public Result<AppScenicOrderDTO> findScenicOrderInfoByNumber(@PathVariable("number") String number){
        return iAppScenicOrderService.findScenicOrderInfoByNumber(number);
    }

    @ApiOperation(value = "景点门票-填写订单页-核对订单", notes = "景点门票-填写订单页-核对订单")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "景点门票-填写订单页-核对订单", operDesc = "景点门票-填写订单页-核对订单")
    @PostMapping(value = "/checkOrder")
    public Result addOrderInfo(@RequestBody ScenicAddCheckOrderReq scenicAddCheckOrderReq){
        return iAppScenicOrderService.addOrderInfo(scenicAddCheckOrderReq,getCurrentUserAllowNotLogIn(getRequest())!=null?getCurrentUserAllowNotLogIn(getRequest()).getId():null);
    }

    @ApiOperation(value = "景点门票-新增景点门票外挂订单", notes = "景点门票-新增景点门票外挂订单")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "景点门票-新增景点门票外挂订单", operDesc = "景点门票-新增景点门票外挂订单")
    @PostMapping(value = "/addManualOrder")
    public Result<Long> addManualOrder(@RequestBody ScenicManualOrderReq scenicManualOrderReq){
        return iAppScenicOrderService.addManualOrder(scenicManualOrderReq,getCurrentUserAllowNotLogIn(getRequest()).getId(),getCurrentUserAllowNotLogIn(getRequest()));
    }

    @ApiOperation(value = "景点门票-填写订单页-积分汇率换港币", notes = "景点门票-填写订单页-积分汇率换港币")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "景点门票-填写订单页-积分汇率换港币", operDesc = "景点门票-填写订单页-积分汇率换港币")
    @GetMapping(value = "/conversionIntegral/{integral}")
    public Result<ScenicOrderIntegralExchangeDTO> conversionIntegral(@PathVariable Long integral){
        return iAppScenicOrderService.conversionIntegral(integral);
    }

    @ApiOperation(value = "景点门票-支付页面-查询订单金额与时间", notes = "景点门票-支付页面-查询订单金额与时间")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "景点门票-支付页面-查询订单金额与时间", operDesc = "景点门票-支付页面-查询订单金额与时间")
    @GetMapping(value = "/queryOrderInfo/{orderId}")
    public Result<ScenicOrderPayQueryInfoDTO> queryOrderInfo(@PathVariable Long orderId){
        return iAppScenicOrderService.queryOrderInfo(orderId);
    }

    @ApiOperation(value = "景点门票-支付页面-下单", notes = "景点门票-支付页面-下单")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "景点门票-支付页面-下单", operDesc = "景点门票-支付页面-下单")
    @PostMapping(value = "/add/order")
    public Result payOrder(@RequestBody List<ScenicPayOrderCollectionReq> reqList){
        return iAppScenicOrderService.payOrder(reqList,getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value = "订单中心景点门票列表", notes = "订单中心景点门票列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "订单中心景点门票列表", operDesc = "订单中心景点门票列表")
    @PostMapping(value = "/list")
    public Result<PageResponse<ScenicOrderDTO>> list(@RequestBody ScenicOrderReq scenicOrderReq){
        return Result.success(iAppScenicOrderService.list(scenicOrderReq,getCurrentUser(getRequest())));
    }

    @ApiOperation(value = "订单中心景点门票详情", notes = "订单中心景点门票详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "订单中心景点门票详情", operDesc = "订单中心景点门票详情")
    @PostMapping(value = "/scenicOrderDetail")
    public Result<ScenicOrderDetailDTO> scenicOrderDetail(@RequestBody ScenicOrderDetailReq scenicOrderDetailReq){
        return iAppScenicOrderService.scenicOrderDetail(scenicOrderDetailReq);
    }

    @ApiOperation(value = "订单中心-景点门票收款", notes = "订单中心-景点门票收款")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "订单中心-景点门票收款", operDesc = "订单中心-景点门票收款")
    @PostMapping(value = "/collection")
    public Result collection(@RequestBody @Valid Scenic0rderCollectionDetailReq scenic0rderCollectionDetailReq){
        return iAppScenicOrderService.scenicOrderCollection(scenic0rderCollectionDetailReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "取消订单（待付款状态）", notes = "取消订单（待付款状态）")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "取消订单（待付款状态）", operDesc = "取消订单（待付款状态）")
    @PostMapping(value = "/cancel-scenic-order")
    public Result<Long> cancelScenicOrder(@RequestBody @Valid Scenic0rderCancelReq scenic0rderCancelReq){
        return iAppScenicOrderService.cancelScenicOrder(scenic0rderCancelReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="待确认、确认成功、确认失败状态取消订单", notes="待确认、确认成功、确认失败状态取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.VISA, operType = OperationLogType.ADD, operTitle = "取消订单", operDesc = "取消订单")
    @PostMapping("/cancel-refund-order")
    public Result<Long> cancelScenicOrderRefund(@RequestBody @Valid Scenic0rderRefundDetailReq scenic0rderRefundDetailReq) {
        return iAppScenicOrderService.cancelScenicOrderRefund(scenic0rderRefundDetailReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "取消订单-审批", notes = "取消订单-审批")
    @PostMapping(value = "/update-approval-check")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "取消订单-审批", operDesc = "取消订单-审批")
    public Result<Long> check(@RequestBody ScenicOrderCheckReq scenicOrderCheckReq) {

        return iAppScenicOrderService.cancelApproval(scenicOrderCheckReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="确认订单", notes="确认订单")
    @OperationLogAnnotation(operModul = OperationLogModel.VISA, operType = OperationLogType.ADD, operTitle = "确认订单", operDesc = "确认订单")
    @PostMapping("/confirm_order")
    public Result<Long> confirmOrder(@RequestBody @Valid ScenicProductOrderReq scenicProductOrderReq) {
        return iAppScenicOrderService.confirmOrder(scenicProductOrderReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="通知旅客", notes="通知旅客")
    @OperationLogAnnotation(operModul = OperationLogModel.VISA, operType = OperationLogType.ADD, operTitle = "确认订单", operDesc = "确认订单")
    @PostMapping("/notice")
    public Result notice(@RequestBody @Valid Scenic0rderNoticeReq scenic0rderNoticeReq) {
        return iAppScenicOrderService.notice(scenic0rderNoticeReq);
    }
}
